package com.aob.controller;

import com.alibaba.fastjson.JSON;
import com.aob.service.RegisterService;
import com.aob.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/start")
public class StartController {

    @Autowired
    private RegisterService registerService;

    @RequestMapping(value = "/a",method = RequestMethod.GET)
    public String register(){
        return "register";
    }

    @RequestMapping(value = "/getEmailCode",method = RequestMethod.POST)
    @ResponseBody
    public String getEmailCode(String email,String inCode){
        BaseResult baseResult = new BaseResult();
        if(registerService.sendEmailCode(email,inCode)){
            baseResult.setMessage("Email发送成功!");
            baseResult.setStatus("200");
            baseResult.setData(true);
        }else{
            baseResult.setMessage("Email发送失败!");
            baseResult.setStatus("407");
            baseResult.setData(false);
        }
        return JSON.toJSONString(baseResult);
    }

    @RequestMapping(value = "/getPhoneCode",method = RequestMethod.POST)
    @ResponseBody
    public String getPhoneCode(String phone,String inCode){
        BaseResult baseResult = new BaseResult();
        if(registerService.sendPhoneCode(phone,inCode)){
            baseResult.setMessage("SMS发送成功!");
            baseResult.setStatus("200");
            baseResult.setData(true);
        }else{
            baseResult.setMessage("SMS发送失败!");
            baseResult.setStatus("407");
            baseResult.setData(false);
        }
        return JSON.toJSONString(baseResult);
    }
}
